﻿define(function (require, exports, module) {
    var Config = require('config');
    var ImageStorage = require('imageStorage');
    var Canvas = require('canvas');
    var m_areaCanvas = Canvas.Get(4);

    function Area(data) {
        this.Data = data;
    };

    Area.prototype.GetLeft = function (left) {
        'number' == typeof left || (left = 0);
        return this.Data.X - left;
    };

    Area.prototype.GetTop = function (top) {
        'number' == typeof top || (top = 0);
        return this.Data.Y - top;
    };

    Area.prototype.Render = function (left, top) {
        RenderAsync(this, left, top).start();
    };

    var RenderAsync = eval(Wind.compile('async', function (_this, left, top) {
        var img = $await(ImageStorage.GetAsync(_this.Data.Img));
        m_areaCanvas.Call('drawImage', img, _this.GetLeft(left), _this.GetTop(top), Config.GetAreaLength(), Config.GetAreaLength());
    }));

    module.exports = Area;
});